package com.weather.web.business;

import com.weather.business.domain.NmCrops;
import com.weather.business.service.INmCropsService;
import com.weather.common.annotation.Log;
import com.weather.common.core.controller.BaseController;
import com.weather.common.core.domain.AjaxResult;
import com.weather.common.core.page.TableDataInfo;
import com.weather.common.enums.BusinessType;
import com.weather.common.utils.SecurityUtils;
import com.weather.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 养殖日期Controller
 *
 * @author ruoyi
 * @date 2024-03-16
 */
@RestController
@RequestMapping("/business/crops")
public class NmCropsController extends BaseController
{
    @Autowired
    private INmCropsService nmCropsService;


    /**
     * 查询养殖日期列表
     */

    @GetMapping("/list")
    public TableDataInfo list(NmCrops nmCrops)
    {
        startPage();
        if (!SecurityUtils.hasRole("admin"))
        {
            nmCrops.setUserId(SecurityUtils.getUserId());
        }
        List<NmCrops> list = nmCropsService.selectNmCropsList(nmCrops);
        return getDataTable(list);
    }

    /**
     * 查询养殖日期列表
     */
    @GetMapping("/all")
    public List<NmCrops> all(NmCrops nmCrops)
    {
        if (!SecurityUtils.hasRole("admin"))
        {
            nmCrops.setUserId(SecurityUtils.getUserId());
        }
        List<NmCrops> list = nmCropsService.selectNmCropsList(nmCrops);
        return list;
    }

    /**
     * 导出养殖日期列表
     */

    @Log(title = "养殖日期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NmCrops nmCrops)
    {
        List<NmCrops> list = nmCropsService.selectNmCropsList(nmCrops);
        ExcelUtil<NmCrops> util = new ExcelUtil<NmCrops>(NmCrops.class);
        util.exportExcel(response, list, "养殖日期数据");
    }

    /**
     * 获取养殖日期详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(nmCropsService.selectNmCropsById(id));
    }

    /**
     * 新增养殖日期
     */

    @Log(title = "养殖日期", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NmCrops nmCrops)
    {
        return toAjax(nmCropsService.insertNmCrops(nmCrops));
    }

    /**
     * 修改养殖日期
     */

    @Log(title = "养殖日期", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NmCrops nmCrops)
    {
        return toAjax(nmCropsService.updateNmCrops(nmCrops));
    }

    /**
     * 删除养殖日期
     */

    @Log(title = "养殖日期", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nmCropsService.deleteNmCropsByIds(ids));
    }
}
